package com.uusee.crawler.job;

import com.uusee.crawler.dbwriter.UgcDbWriter;
import com.uusee.crawler.fetcher.FetchHTTP;
import com.uusee.crawler.framework.Job;
import com.uusee.crawler.model.CrawlURI;
import com.uusee.crawler.pageprocessor.video.PlayPageProcessor;
import com.uusee.crawler.xmlwriter.UgcXmlWriter;
import com.uusee.shipshape.sp.model.Ugc;

public class SinaUgcCrawlJob implements Job {
	private FetchHTTP fetch = new FetchHTTP();
	private PlayPageProcessor pageProcessor = new PlayPageProcessor();
	private UgcXmlWriter xmlWriter = new UgcXmlWriter();
	private UgcDbWriter dbWriter = new UgcDbWriter();

	public CrawlURI createCrawlURI(String evid) {
		String playUrl = "http://you.video.sina.com.cn/b/"+evid+".html";
		Ugc ugc = new Ugc();
		ugc.setEvid(evid+"");
		ugc.setVideoSite("v.sina.com.cn");
		ugc.setPlayUrl(playUrl);
		
		CrawlURI crawlURI = new CrawlURI();
		crawlURI.setSourceSite("v.sina.com.cn");
		crawlURI.setCrawlUrl(playUrl);
		crawlURI.setModel(ugc);
		crawlURI.setCharset("utf-8");
		return null;
	}

	public void crawl(CrawlURI crawURI) {
		try {
			fetch.process(crawURI);
			pageProcessor.process(crawURI);
			// xmlwriter.process(crawURI);
			dbWriter.process(crawURI);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setFetch(FetchHTTP fetch) {
		this.fetch = fetch;
	}

	public void setPageProcessor(PlayPageProcessor pageProcessor) {
		this.pageProcessor = pageProcessor;
	}

	public void setXmlWriter(UgcXmlWriter xmlWriter) {
		this.xmlWriter = xmlWriter;
	}

	public void setDbWriter(UgcDbWriter dbWriter) {
		this.dbWriter = dbWriter;
	}

}
